<template>
  <div :class="appContainerCssClass">
    <div class="filter-container">
      <a-form-model ref="ruleForm" :model="formModel" layout="inline">
        <a-row v-for="(rowItem ,rowIndex) in formRowCollapseKey['noCollapseKey']" :key="rowIndex" :gutter="rowItem.gutter">
          <a-col v-for="(formItem,colIndex) in formRowActiveData[rowItem.rowKey].colList" :key="colIndex" :span="formItem.span">
            <input-tpl-ui
              v-show="rowItem.rowType === 'form'"
              ref="modalFormTplUi"
              :param-data="initData"
              :form-item="formColActiveData[formItem.model]"
              :active-enum-list="activeEnumData[formItem.model]"
              :active-enum-data="activeEnumData"
              :modal-fn-data="modalFn"
              :ui-page-url="uiPageUrl"
              :init-src-label="initSrcObj.initSrcLabel"
              :rules="rules"
              :modal-form="formModel"
              :form-event="formEvent"
              @selectSearch="inputSelectSearch"
              @inputSearch="inputSearch"
              @changeEvent="inputChangeEvent"
              @clearEmpty="clearEmpty"
            />
          </a-col>
        </a-row>
      </a-form-model>
    </div>

    <!--    <operator-btn-tpl-list-->
    <!--      :session-config-tpl-data="sessionConfigTplData"-->
    <!--      :toolbar-menu-data="initToolbarMenu"-->
    <!--      :toolbar-list-data="tableToolbarList"-->
    <!--      :table-selected-key-data="tableSelectedKey"-->
    <!--      @tableOperatorBtnOnClick="tableOperatorBtnOnClick"-->
    <!--    />-->

    <operator-btn-tpl-list
      :session-config-tpl-data="sessionConfigTplData"
      :toolbar-menu-data="tableToolbarMenu"
      :toolbar-list-data="tableToolbarList"
      :table-selected-key-data="tableSelectedKey"
      :ui-page-url="uiPageUrl"
      @tableOperatorBtnOnClick="tableOperatorBtnOnClick"
      @tableOperatorBtnUpload="tableOperatorBtnUpload"
    />

    <a-dropdown :trigger="[this.treeDropTrigger]" @visibleChange="treeDropStatus">
      <a-tree
        :ref="tableId"
        :show-line="treeShowLine"
        :checkable="checkable"
        :loading="loading"
        :tree-data="tableData"
        :load-data="onLoadTreeData"
        :expanded-keys="expandedKeys"
        :auto-expand-parent="autoExpandParent"
        :loaded-keys="expandedKeys"
        disabled="true"
        @expand="onExpand"
        @select="tableOnSelect"
        @rightClick="rightClickHandle"
        @check="tableOnCheck"
      />
      <a-menu slot="overlay">
        <a-menu-item v-for="(menuItem,index) in tableColumnMenu" :key="menuItem.key" @[menuItem.eventName]="columnBtnOnClick(menuItem, null)">
          {{ menuItem.name }}
        </a-menu-item>
      </a-menu>
    </a-dropdown>
  </div>
</template>
<script>
import { submitDealReq, getRowsFieldValue } from '@/utils/auth'
// import { executeRecord, deleteRecord, batchDeleteRecord } from '@/utils/hyrecord'
import { executeRecord, getGlobalParam, deleteLocalList, deleteBatchLocalList, deleteBatchRemoteRecord, deleteRemoteRecord } from '@/utils/hyrecord'
import { initToolbar, changeToolbar, initToolbarMenu, changeToolbarMenu, initColumnListBtn, changeTreeColumnMenu } from '@/utils/hybtn'
import { initEnumParam, initEnum, changeLoadEnumList } from '@/utils/hyenum'
import { getRefOpenObj, getOpenLocalFormModel } from '@/utils/hyopen'
import { initDealApi } from '@/utils/hyurl'
import { initRules, changeFormRules, changeFormKeyRules,initLazyFormRules } from '@/utils/hyformrules'
import { initForm, changeForm, handleInit, initFormFnParam, changeFormFnParam, changeFormKeyFnParam } from '@/utils/hyform'
import { initColumnList, changeColumnList, initTableEvent, changeTableEvent } from '@/utils/hylist'
import { fetchTreeData } from '@/utils/hytree'
import { inputChangeEventControlObj, getCallFnByFnType, inputChangeEvent, execClickBtn } from '@/utils/hyctr'
import inputTplUi from './inputTplUi'
import operatorBtnTplList from './operatorBtnTplList'
import { btnUploadFile } from '@/utils/hyupload'
import vm from 'vm'
// import { getGlobalParam } from '../../../../utils/hyrecord'
const tableColumns = []
export default {
  name: 'TreeTplView',
  components: {
    inputTplUi, operatorBtnTplList
  },
  props: ['S_PAGE_ID', 'S_PAGE_VER', 'S_PARTITION', 'tableTplListUiData', 'tableEvent', 'tableId', 'paramData', 'tableObjParam', 'uiPageUrl', 'tableEchartId', 'appContainnerCssObj', 'defPanelWidth'],
  data() {
    return {
      appContainerCssClass: 'app-container',
      appDefaultContainerCssClass: 'app-container',
      appInnerContainerCssClass: 'app-inner-container',
      globalData: {},
      triggerOpenParam: {},
      initLoadObj: { loadFormId: '', loadBtnId: '', loadListId: '' , panelWidth: 100},
      initSrcObj: { initSrcUrl: 'list', initSrcLabel: 'normal' },
      lazyFormRules: {},
      initFormKey: 'formList',
      initTableKey: 'treeTplList',
      initTableEvent: {},
      treeDisabled: true,
      clientWidth: 920,
      rules: { },
      openParam: {},
      initData: {}, // 查询条件初始化数据
      remoteDataSet: {},
      openReturnData: {}, // 开窗返回参数
      expandedKeys: [],
      autoExpandParent: true,
      inputStyle: 'width: 260px',
      loadingChildren: false,
      loading: false,
      checkable: false,
      treeShowLine: true,
      menuVisible: false,
      props: {
        label: 'title',
        id: 'key',
        children: 'children',
        isLeaf: 'leaf'
      },
      selection: [],
      selectCellRow: null,
      selectCellCol: null,
      selectCell: null,
      pagination: {
        size: 10,
        num: 1
      },
      total: 0,
      queryParams: {},
      tableExtProp: {},
      modalFn: {},
      modalFnShow: {},
      toolbarFn: {},
      rowSelectType: 'checkbox',
      // tableSearchForm:{I_PAGE_TYPE:0},
      tableWhereFormToolbar: [],
      tableSelectTips: false,
      // tableId:'table',
      tableScroll: { x: 550 },
      tableDividerType: 'vertical',
      tableBordered: true,
      tableRowKey: 'S_ID',
      tableSize: 'middle',
      tableLoading: false,
      tableRightMenu: { update: true, delete: false, insert: true, insertRoot: true, select: false, copy: false, detail: false },
      tableFirstRow: {},
      tableSelectedKey: [],
      tableSelectedRow: [],
      tableCheckedKey: [],
      tableCheckedRow: [],
      tableSelectedNode: null,
      tableDropTrigger: '',
      tableQueryParam: { key: '0' },
      enumParam: {},
      tableEnumData: {},
      tableColumns: [],
      tableData: [],
      formList: [],
      sessionConfigTplData: [],
      initBtnData: {},
      // initToolbarMenu: [],
      // initToolbarList: [],
      initColumnMenu: [],
      initColumnBtn: [],

      tableToolbarMenu: [],
      tableToolbarList: [],

      tableColumnMenu: [],
      tableColumnBtn: [],
      customRowIdxBtnObj: {},
      customRowIdxMenuObj: {},

      formModel: {},
      formEvent: {},
      formShow: {},
      colShow: {},
      rowShow: {},
      formRowData: {},
      formColData: {},
      // tableSearchForm: this.$form.createForm(this),
      validatorRules: {
        departName: { rules: [{ required: true, message: '!' }] }
      },
      dealApi: {
        list: { S_PAGE_ID: '', S_PAGE_VER: 'v0.02', S_PARTITION: 32 }
      },
      dealParam: {
        list: { S_DY_PARAM: [] }
      },
      treeDropTrigger: '',
      enumData: {},
      sessionFilterList: '',
      sessionTplId: '',
      columnBtnAction: {},
      showAction: ['action'],
      showTags: ['I_FLAG_text'],
      showInputs: ['S_ID'],
      columnOrderParam: {},
      columnFilterParam: {},
      activeEnumData: {},
      activeFilters: [],
      columnFiltersData: {},
      activeColumnFiltersData: {},
      formRowCollapseKey: {},
      formRowActiveData: {},
      formColActiveData: {},
      listColActiveList: [],
      listColActiveData: {}
    }
  },
  watch: {
    paramData(val) {
      const _this = this
      console.log('paramData 0000000000000000', val)
      _this.setTableSearchForm(val)
      _this.$nextTick(() => {
        _this.searchQuery()
      })
    }
  },
  mounted() {
    // 延迟加载采用mounted重新挂载
    this.clientWidth = document.body.clientWidth
    if (undefined === this.tableTplListUiData) {
      return
    }
    this.initUI(this.tableTplListUiData, this.paramData, this.initSrcObj)
    if (undefined === this.paramData) {
      return
    }
    if (Object.keys(this.paramData).length !== 0) {
      this.tableOnLoadData()
    }
  },
  methods: {
    changeAppContainnerCssObj() {
      this.appContainerCssClass = this.appInnerContainerCssClass
    },
    changeCheckable() {
      if (undefined !== this.initSrcObj.initSrcType) {
        if (this.initSrcObj.initSrcType === 'checkbox') {
          this.checkable = true
        } else {
          this.checkable = false
        }
      }
    },
    getLocalParamDataSet() {
      // 入参数据集
      const thisObj = this
      const record = Object.assign({}, thisObj.openParam, thisObj.initData, thisObj.openReturnData, thisObj.formModel)
      return record
    },
    changePanelInitUiVal(formItem, triggerObj) {
      // 变更呈现数据
      const selectedRow = this.tableSelectedRow
      const localParamDataSet = this.getLocalParamDataSet()
      this.$emit('tableChangeEvent', formItem, triggerObj, localParamDataSet, selectedRow)
    },
    changeUiEventTrigger(formItem, triggerObj) {
      const selectedRow = this.tableSelectedRow
      const localParamDataSet = this.getLocalParamDataSet()
      this.$emit('uiChangeEvent', formItem, triggerObj, localParamDataSet, selectedRow)
    },
    changeColumnList(formItem, triggerObj) {
      const thisObj = this
      changeColumnList(thisObj, triggerObj, this.formModel)
    },
    changeForm(triggerObj, param) {
      const thisObj = this
      changeForm(thisObj, triggerObj, param)
    },
    otherCompSetValClearData() {
      const thisObj = this
      const tmpData = Object.assign({})
      thisObj.tableQueryParam = Object.assign(tmpData)
      thisObj.initData = Object.assign(tmpData)
      thisObj.openReturnData = Object.assign(tmpData)
      thisObj.formModel = Object.assign(tmpData)
      thisObj.globalData = Object.assign(tmpData)
    },
    otherCompSetValOpenParam(triggerObj, param, initSrcObj) {
      // const thisObj = this
      // this.otherCompSetValClearData()
      // this.openParam = Object.assign({}, param)
      // thisObj.formModel = Object.assign({}, this.openParam, param)
      // const record = thisObj.getLocalParamDataSet()
      // console.log('otherCompSetValOpenParam 本地参数', record)
      // this.tableQueryByParam(record)
      // this.changeToolbar(triggerObj)

      const thisObj = this
      this.otherCompSetValClearData()
      this.initSrcObj = initSrcObj
      this.openParam = Object.assign({}, param)
      thisObj.formModel = Object.assign({}, this.openParam, param)
      const tmpGlobalData = {}
      tmpGlobalData.tableId = thisObj.tableId
      tmpGlobalData.initSrcObj = thisObj.initSrcObj
      tmpGlobalData.clickRow = {}
      tmpGlobalData.clickItem = {}
      tmpGlobalData.openParam = param
      tmpGlobalData.formModel = thisObj.formModel
      tmpGlobalData.initData = thisObj.initData
      tmpGlobalData.activeEnumData = thisObj.initData
      tmpGlobalData.tableSelectedRow = []
      tmpGlobalData.globalParam = getGlobalParam(thisObj)
      thisObj.globalData = tmpGlobalData
      this.changeToolbar(triggerObj)
      if (thisObj.initSrcObj.initSrcSearch === undefined || thisObj.initSrcObj.initSrcSearch === true) {
        thisObj.triggerInitBtn()
      }
    },
    changeToolbar(triggerObj) {
      // 设置具体变量字段呈现
      // triggerObj 触发对象,没有填写null
      const thisObj = this
      const record = thisObj.getLocalParamDataSet()
      changeToolbar(thisObj, triggerObj, record)
    },
    // initToolbarMenu() {
    //   // 一开始初始化按钮栏
    //   const thisObj = this
    //   initToolbarMenu(thisObj)
    // },
    changeToolbarMenu(triggerObj) {
      // 设置具体变量字段呈现
      // triggerObj 触发对象,没有填写null
      const thisObj = this
      const record = thisObj.getLocalParamDataSet()
      changeToolbarMenu(thisObj, triggerObj, record)
    },
    changeTreeColumnMenu(triggerObj, globalData) {
      const thisObj = this
      changeTreeColumnMenu(thisObj, triggerObj, globalData)
    },
    initUiLabel(srcLabel) {
      if (undefined === srcLabel || srcLabel === null || srcLabel === '') {
        this.initSrcLabel = 'list'
      } else {
        this.initSrcLabel = srcLabel
      }
    },
    // initRules() {
    //   // 开始初始化所有项目为必填
    //   const thisObj = this
    //   initRules(thisObj)
    // },
    changeFormRules() {
      // 加载结束后,根据规则调整对应表单校验方式
      const thisObj = this
      changeFormRules(thisObj)
    },
    changeFormKeyRules(key) {
      // 单个变量校验规则调整设置
      const thisObj = this
      changeFormKeyRules(thisObj, key)
    },
    // initFormFnParam() {
    //   // 一开始初始化读写参数
    //   const thisObj = this
    //   initFormFnParam(thisObj, true)
    // },
    changeFormFnParam() {
      // 设置初始加载表单读写参数
      const thisObj = this
      changeFormFnParam(thisObj)
    },
    changeFormKeyFnParam(key) {
      const thisObj = this
      changeFormKeyFnParam(thisObj, key)
    },
    // initTblEvent() {
    //   const thisObj = this
    //   initTableEvent(thisObj)
    // },
    initUI(val, param, initSrcObj) {
      const _this = this
      this.initUiVal = val
      this.initLoadObj.loadPanelId = val.panel.panelTplId
      this.initLoadObj.loadPanelVer = val.panel.panelTplVer
      this.initLoadObj.panelWidth = val.panel.panelWidth
      this.initLoadObj.defPanelWidth = this.defPanelWidth
      this.initSrcObj = initSrcObj
      this.openParam = param
      this.formModel = Object.assign({}, this.openParam)
      initLazyFormRules(_this)
      initEnumParam(_this)
      initRules(_this)
      initForm(_this)
      initFormFnParam(_this, true)
      initToolbar(_this)
      initToolbarMenu(_this)
      initColumnList(_this)
      initColumnListBtn(_this)
      initTableEvent(_this)
      this.changeCheckable()
      if (undefined === val || undefined === val.urlList) {
        return
      }
      initDealApi(_this, val)
      // initFormUiData(this, val, srcLabel)
      // initTableUiData(this, val, param)
      this.tableQueryParam = Object.assign({}, this.tableQueryParam, param)
      _this.setTableSearchForm(param)
      _this.$nextTick(() => {
        _this.changeFormRules()
        _this.changeFormFnParam()
        // _this.changeColShow()
        initEnum(_this, _this.openParam)
        _this.changeToolbar(null)
        _this.changeToolbarMenu(null)
        handleInit(_this)
        _this.$nextTick(() => {
          _this.onLoadTreeData(null, null)
        })
      })
    },
    inputChangeEventControlObj(formItem) {
      const thisObj = this
      inputChangeEventControlObj(thisObj, formItem)
    },
    onExpand(expandedKeys) {
      this.expandedKeys = expandedKeys
      this.autoExpandParent = false
    },
    tableOnSelect(selectedKeys, e) {
      const thisObj = this
      thisObj.globalData.clickSrc = 'tableSelectClick'
      thisObj.globalData.tableId = thisObj.tableId
      thisObj.globalData.openParam = thisObj.openParam
      thisObj.globalData.formModel = thisObj.formModel
      thisObj.globalData.initData = thisObj.initData
      thisObj.globalData.clickItem = {}
      if (e.node.dataRef instanceof Array) {
        this.tableSelectedRow = e.node.dataRef
        thisObj.globalData.clickRow = e.node.dataRef[0]
      } else {
        const arrayRow = []
        arrayRow.push(e.node.dataRef)
        this.tableSelectedRow = arrayRow
        thisObj.globalData.clickRow = e.node.dataRef
      }
      thisObj.globalData.globalParam = Object.assign({}, getGlobalParam(thisObj))
      thisObj.globalData.activeEnumData = thisObj.activeEnumData
      thisObj.globalData.tableSelectedRow = this.tableSelectedRow
      this.tableCheckedRow = Object.assign([])
      this.tableSelectedKey = selectedKeys
      this.tableSelectedNode = e.node
      if (this.tableEvent.select !== '') {
        this.tableCheckedRow.push(e.node.dataRef)
        changeTableEvent(thisObj, 'click', '单击事件')
        this.$emit(this.tableEvent.select, thisObj.globalData)
      }
      this.tableRightMenuDeleteClean()
    },
    tableOnCheck(checkedKeys, info) {
      const thisObj = this
      this.tableCheckedRow = Object.assign([])
      this.tableCheckedKey = checkedKeys
      this.tableSelectedKey = checkedKeys
      const checkedNodes = info.checkedNodes
      const checkedNodesLength = checkedNodes.length
      for (let i = 0; i < checkedNodesLength; i++) {
        const node = checkedNodes[i]
        this.tableCheckedRow.push(node.data.props.dataRef)
        this.tableSelectedRow = this.tableCheckedRow
      }

      thisObj.globalData.clickSrc = 'checkClick'
      thisObj.globalData.tableId = thisObj.tableId
      thisObj.globalData.openParam = thisObj.openParam
      thisObj.globalData.formModel = thisObj.formModel
      thisObj.globalData.initData = thisObj.initData
      thisObj.globalData.clickItem = {}
      thisObj.globalData.clickRow = {}
      thisObj.globalData.activeEnumData = thisObj.activeEnumData
      thisObj.globalData.tableSelectedRow = this.tableCheckedRow
      thisObj.globalData.globalParam = getGlobalParam(thisObj)
      if (this.tableEvent.select !== '') {
        // const selectedRow = changeSelectRow(thisObj, this.tableCheckedRow)
        this.$emit(this.tableEvent.select, thisObj.globalData)
      }
    },
    tableRightMenuDeleteClean() {
      if (this.tableSelectedNode !== null) {
        if (this.tableSelectedNode.expanded && this.tableSelectedNode.dataRef.children && this.tableSelectedNode.dataRef.children.length == 0) {
          // this.treeRightMenu.deleteNode = true;
        } else {
          // this.treeRightMenu.deleteNode = false;
        }
      } else {
        // this.treeRightMenu.deleteNode = false;
      }
    },
    rightClickHandle(node) {
      const thisObj = this
      this.treeDropTrigger = 'contextmenu'
      this.tableSelectedKey = node.node.eventKey
      this.tableSelectedNode = node.node
      this.tableCheckedRow = []
      this.tableCheckedRow.push(node.node.dataRef)
      thisObj.globalData.clickSrc = 'columnClick'
      thisObj.globalData.tableId = thisObj.tableId
      thisObj.globalData.openParam = thisObj.openParam
      thisObj.globalData.formModel = thisObj.formModel
      thisObj.globalData.initData = thisObj.initData
      thisObj.globalData.activeEnumData = thisObj.activeEnumData
      thisObj.globalData.clickItem = {}
      if (node.node.dataRef instanceof Array) {
        thisObj.globalData.clickRow = node.node.dataRef[0]
        this.tableSelectedRow = node.node.dataRef
      } else {
        const arrayRow = []
        arrayRow.push(node.node.dataRef)
        this.tableSelectedRow = arrayRow
        thisObj.globalData.clickRow = node.node.dataRef
      }
      thisObj.globalData.tableSelectedRow = this.tableSelectedRow
      thisObj.globalData.globalParam = getGlobalParam(thisObj)
      console.log('thisObj.globalData', thisObj.globalData)
      this.changeTreeColumnMenu(null, thisObj.globalData)
      this.tableRightMenuDeleteClean()
    },
    btnClickEvent(btnItem, record) {
      console.log('record', record)
      if (btnItem.fnType === 97) {
        this.saveSessionFormData(btnItem, record)
      } else {
        this.$emit('btnClickEvent', btnItem, record)
      }
    },
    saveSessionFormData(btnItem, record) {
      const refOpenObj = getOpenLocalFormModel()
      btnItem.refOpen = refOpenObj
      const S_FORM_DATA = JSON.stringify(this.formModel)
      const localFormData = {}
      localFormData.S_FORM_DATA = S_FORM_DATA
      localFormData.S_PAGE_ID_IDX = this.uiPageUrl.S_UI_PAGE_ID_IDX_2025
      localFormData.S_PAGE_VER_IDX = this.uiPageUrl.S_UI_PAGE_VER_IDX_2025
      localFormData.S_BLOCK_TPL_ID = this.initLoadObj.loadFormId
      this.$emit(this.tableEvent.generalModal, btnItem, localFormData)
    },
    treeDropStatus(visible) {
      // 右键点击下拉框改变事件
      if (visible === false) {
        this.treeDropTrigger = ''
      }
    },
    // 右键关闭下拉框
    treeCloseDrop() {
      this.treeDropTrigger = ''
    },

    selectFirstRow() {
      const _this = this
      if (undefined !== _this.tableObjParam) {
        _this.$emit(_this.tableObjParam.selectFirstRow, this.tableFirstRow)
      }
    },
    clearEmpty(item) {
      console.log('00000000000000', item)
    },
    changeUploadFile(btnItem) {
      this.nowBtnItem = btnItem
    },
    importFileData(btnItem, data) {
      console.log('点击导入文件事件.', btnItem)
    },
    tableOperatorBtnUpload(btnItem, data) {
      console.log('点击导入文件事件.上传', btnItem)
      const thisObj = this
      btnUploadFile(thisObj, btnItem, data)
    },
    inputChangeEvent(formItem) {
      const thisObj = this
      inputChangeEvent(thisObj, formItem)
    },
    inputOpenGeneralModal(formItem, record) {
      this.$emit('openGeneralModal', formItem, record)
    },
    triggerInitBtn() {
      const thisObj = this
      if (thisObj.initUiVal.toolbar !== undefined &&
        thisObj.initUiVal.toolbar.initBtnKey !== undefined &&
        thisObj.initUiVal.toolbar.initBtnKey.length > 0
      ) {
        const initBtnKey = thisObj.initUiVal.toolbar.initBtnKey
        for (const i in initBtnKey) {
          const btnKey = initBtnKey[i]
          console.log('触发初始化', btnKey)
          execClickBtn(thisObj, thisObj.globalData, btnKey)
        }
      } else {
        thisObj.tableQueryByParam(thisObj.globalData)
      }
    },
    inputSearch(formItem, data) {
      const thisObj = this
      thisObj.triggerInitBtn()
    },
    inputSelectSearch(formItem, data) {
      const thisObj = this
      console.log('inputSelectSearch', formItem, data)
      // console.log('inputSelectSearch globalData', thisObj.globalData, thisObj.formModel)

      const triggerObj = {}
      triggerObj.s_RULE_TPL_KEY = formItem.model
      const param = {}
      thisObj.globalData.globalParam[formItem.model] = data
      thisObj.globalData.formModel[formItem.model] = data
      changeLoadEnumList(thisObj, triggerObj, param)
    },
    getRowFieldValue(selectionRows, field) {
      return getRowsFieldValue(selectionRows, field)
    },
    triggerQuickSelectEvent(selectionRows, formItem, eventObject) {
      const _this = this
      const param = this.getTableSearchForm()
      const list = []
      for (const i in selectionRows) {
        const row = selectionRows[i]
        list.push(row)
      }
      param[eventObject.key] = list
      this.loading = true
      return submitDealReq(param).then((res) => {
        this.loading = false
        if (res.data.success) {
          _this.$message.success(res.data.message)
        } else {
          _this.$message.warning(res.data.message)
        }
      })
    },
    getCallFnByFnType(btnItem) {
      this.nowBtnItem = btnItem
      return getCallFnByFnType(btnItem)
    },
    columnBtnOnClick(btnItem, record) {
      const thisObj = this
      thisObj.globalData.clickSrc = 'columnClick'
      thisObj.globalData.tableId = thisObj.tableId
      thisObj.globalData.initSrcObj = thisObj.initSrcObj
      thisObj.globalData.clickItem = btnItem
      thisObj.globalData.openParam = thisObj.openParam
      thisObj.globalData.formModel = thisObj.formModel
      thisObj.globalData.initData = thisObj.initData
      thisObj.globalData.activeEnumData = thisObj.activeEnumData
      thisObj.globalData.globalParam = getGlobalParam(thisObj)

      const fn = thisObj.getCallFnByFnType(btnItem)
      console.log('fn', fn)
      if (fn) {
        this[fn](btnItem, thisObj.globalData)
      } else {
        this.$message.warning('按钮未配置响应函数')
      }
    },
    tableOperatorBtnOnClick(btnItem) {
      const thisObj = this
      // 按钮条事件响应
      thisObj.globalData.clickSrc = 'toolbarClick'
      thisObj.globalData.tableId = thisObj.tableId
      thisObj.globalData.initSrcObj = thisObj.initSrcObj
      thisObj.globalData.clickRow = {}
      thisObj.globalData.clickItem = btnItem
      thisObj.globalData.openParam = thisObj.openParam
      thisObj.globalData.formModel = thisObj.formModel
      thisObj.globalData.initData = thisObj.initData
      thisObj.globalData.activeEnumData = thisObj.activeEnumData
      thisObj.globalData.tableSelectedRow = this.tableCheckedRow
      thisObj.globalData.globalParam = getGlobalParam(thisObj)
      const fn = thisObj.getCallFnByFnType(btnItem)
      this[fn](btnItem, thisObj.globalData)
    },
    setTableSearchForm(param) {
      const _this = this
      _this.formModel = Object.assign({}, this.formModel, param)
    },
    getTableSearchForm() {
      return this.formModel
    },
    searchQuery() {
      this.tableSelectedNode = null
      this.tableOnLoadData()
    },
    tableQueryByParam(param) {
      const _this = this
      _this.formModel = Object.assign({}, this.formModel, param)
      _this.tableQueryParam = Object.assign({}, this.tableQueryParam, param)
      _this.$nextTick(() => {
        _this.tableOnLoadData()
      })
    },
    openGeneralModal(btnItem, globalData) {
      console.log('openGeneralModal',btnItem)
      const refOpenObj = getRefOpenObj(this, btnItem, globalData)
      if (refOpenObj !== null) {
        btnItem.refOpen = Object.assign({}, refOpenObj)
        // if (this.tableEvent.generalModal !== '') {
        this.$emit(this.tableEvent.generalModal, btnItem, globalData)
        // }
      } else {
        this.$message.warning('无满足条件开窗数据,请联系管理员.')
      }
    },
    getTableData() {
      return this.tableData
    },
    tableMenuSelect() {
      console.log('添加选择')
      this.$emit('openTableMenuSelect', this.tableSelectedRow)
    },
    tableSelectedTitle() {
      return !this.tableSelectedRow.title ? '' : this.tableSelectedRow.title
    },
    tableClearSelected() {
      this.hiding = true
      this.tableSelectTips = false
      this.tableSelectedRow = []
      this.tableSelectedKey = []
    },
    openTableUpload(btnItem, record) {
      this.$emit(this.tableEvent.impModal, btnItem, record, this.dealApi)
    },
    // openTableDownLoad(btnItem, record) {
    //   const _this = this
    //   let param = {}
    //   if (record !== undefined) {
    //     param = Object.assign({}, record)
    //   }
    //   param.url = '/run/ctr/submitExportXls/'
    //   param.iPageNo = 1
    //   param.iPageSize = 500
    //   param = Object.assign({}, param, _this.dealApi.expUrl)
    //   this.openTableExport(param)
    // },
    // openTableDownLoadTemplate(btnItem, record) {
    //   const _this = this
    //   let param = {}
    //   if (record !== undefined) {
    //     param = Object.assign({}, record)
    //   }
    //   param.url = '/run/ctr/submitUploadTemplate/'
    //   param.iPageNo = 1
    //   param.iPageSize = 1
    //   param = Object.assign({}, param, _this.dealApi.impUrl)
    //   this.openTableExport(param)
    // },
    // openTableExport(param) {
    // },
    // openTableLoad(btnItem, record) {
    //   const _this = this
    //   if (undefined === btnItem.urlKey || btnItem.urlKey === null || btnItem.urlKey === '') {
    //     btnItem.urlKey = 'load'
    //   }
    //   _this.execute(btnItem, record)
    // },
    // openTableMenuLoad(btnItem, record) {
    //   const _this = this
    //   if (undefined === btnItem.urlKey || btnItem.urlKey === null || btnItem.urlKey === '') {
    //     btnItem.urlKey = 'menuLoad'
    //   }
    //   _this.execute(btnItem, record)
    // },
    // submitDealConfirmReq(btnItem, record) {
    //   const thisObj = this
    //   const newTmp = getCheckRecordParam(thisObj, btnItem, record)
    //   deleteRecord(thisObj, btnItem, null, newTmp)
    // },
    execute(btnItem, record) {
      executeRecord(this, btnItem, record)
    },
    searchList() {
      console.log('树形查询函数')
      this.search()
    },
    searchPage() {
      console.log('树形查询函数')
      this.search()
    },
    tableOnLoadData(btnItem) {
      this.search(btnItem)
    },
    search(btnItem) {
      if (this.tableSelectedNode === null) {
        this.onLoadTreeData(null, null, btnItem)
      } else if (this.tableSelectedNode.$parent !== undefined) {
        if (this.tableSelectedNode.$parent.dataRef === undefined) {
          // 当前操作根节点数据
          this.onLoadTreeData(null, null, btnItem)
        } else {
          this.onLoadTreeData(this.tableSelectedNode.$parent, null, btnItem)
        }
      } else {
        this.onLoadTreeData(null, null, btnItem)
      }
    },
    onLoadTreeData(node, resolve, btnItem) {
      let record = {}
      if (node !== undefined && node !== null) {
        record = node.dataRef
      }
      const thisObj = this
      thisObj.globalData.tableSelectedRow = []
      thisObj.globalData.openParam = thisObj.openParam
      thisObj.globalData.formModel = thisObj.formModel
      thisObj.globalData.initData = thisObj.initData
      thisObj.globalData.clickRow = record
      thisObj.globalData.clickItem = btnItem
      thisObj.globalData.activeEnumData = thisObj.activeEnumData
      thisObj.globalData.globalParam = getGlobalParam(thisObj)
      return fetchTreeData(this, node, resolve)
    },
    loadNode(node, resolve) {
      if (node.level === 0) {
        return
      }
      if (node.level > 0) {
        this.onLoadTreeData(node, resolve)
      }
    },
    executeBatchRemoteDelete(btnItem, globalData) {
      deleteBatchRemoteRecord(this, globalData)
    },
    executeRemoteDelete(btnItem, globalData) {
      // 本地删除
      deleteRemoteRecord(this, globalData)
    },
    executeBatchLocalDelete(btnItem, globalData) {
      deleteBatchLocalList(this, globalData)
    },
    executeLocalDelete(btnItem, globalData) {
      // 本地删除
      deleteLocalList(this, globalData)
    },
    reloadLoadData(openBtnItem, returnData, modalKey, modalForm) {
      console.log('modalKey', modalKey, openBtnItem)
      if (modalKey === 'insert') {
        this.insertSuccess(openBtnItem, returnData, modalKey, modalForm)
      } else if (modalKey === 'update') {
        this.updateSuccess(openBtnItem, returnData, modalKey, modalForm)
      } else if (modalKey === 'delete') {
        this.deleteSuccess(openBtnItem, returnData, modalKey, modalForm)
      } else if (modalKey === 'remoteData') {
        this.remoteDataSuccess(openBtnItem, returnData, modalKey, modalForm)
      } else {
        this.remoteDataSuccess(openBtnItem, returnData, modalKey, modalForm)
      }
    },
    remoteDataSuccess(btnItem, returnData, modalKey, modalForm) {
      this.search(btnItem)
    },
    insertSuccess(btnItem, returnData, modalKey, modalForm) {
      if (this.tableSelectedNode === null) {
        this.onLoadTreeData(null, null, null)
      } else if (this.tableSelectedNode) {
        this.onLoadTreeData(this.tableSelectedNode, null, null)
      } else {
        this.onLoadTreeData(null, null, null)
      }
    },
    updateSuccess(btnItem, returnData, modalKey, modalForm) {
      if (this.tableSelectedNode.$parent.dataRef === undefined) {
        this.onLoadTreeData(null, null, null)
      } else {
        this.onLoadTreeData(this.tableSelectedNode.$parent, null, btnItem)
      }
    },
    deleteSuccess(btnItem, returnData, modalKey, modalForm) {
      console.log('this.modalForm', modalForm)
      console.log('this.tableSelectedNode', this.tableSelectedNode)
      console.log('this.tableSelectedNode.$parent', this.tableSelectedNode.$parent)
      console.log('this.tableSelectedNode.$parent.dataRef', this.tableSelectedNode.$parent.dataRef)
      if (this.tableSelectedNode === null) {
        this.onLoadTreeData(null, null, null)
      } else if (this.tableSelectedNode.$parent !== undefined) {
        if (this.tableSelectedNode.$parent.dataRef === undefined) {
          // 根节点刷新
          this.onLoadTreeData(null, null, null)
        } else {
          // 上级节点刷新
          this.onLoadTreeData(this.tableSelectedNode.$parent, null, null)
        }
      } else {
        this.onLoadTreeData(null, null, null)
      }
    }
  }
}
</script>
<style>
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>
